﻿using System;
using System.ComponentModel;
using System.Reflection;

namespace Moqikaka.Util
{
    /// <summary> 
    /// 反射帮助类
    /// </summary>
    public class ReflectionUtil
    {
        /// <summary>
        /// 获取枚举注释
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="e"></param>
        /// <returns></returns>
        public static String GetEnumDesc<T>(T e)
        {
            FieldInfo EnumInfo = e.GetType().GetField(e.ToString());
            DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])EnumInfo.
                GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (EnumAttributes.Length > 0)
            {
                return EnumAttributes[0].Description;
            }
            return e.ToString();
        }
        
    }
}
